import { comsType } from "../../constants/form";

const {
  FORM_FOOTER, FORM_HEADER, FOOTER,
  DATATABLE, COLUMNPANEL2, COLUMNPANEL3, TABLELAYOUT,
  COMBOBOX, SELECT, ATTACHMENT, PICTURE, SIGNATURE, MOBILE, MAP, ADDRESS
} = comsType;

const _type = (comTypes, not = false) => {
  return com => {
    const isexist = !!com && ~comTypes.indexOf(com.type);

    if (not) return !isexist;

    return isexist;
  }
};

// 布局组件
const layoutComs = [COLUMNPANEL2, COLUMNPANEL3, TABLELAYOUT];
// 容器组件
const wrapperComs = [DATATABLE, ...layoutComs];

export const isNormal = _type([FORM_FOOTER, FORM_HEADER, FOOTER], true);
export const isFormHeader = _type(FORM_HEADER);
export const isFormFooter = _type(FORM_FOOTER);
export const isFooter = _type(FOOTER);
export const isOptional = _type([COMBOBOX, SELECT]);
export const isAttachment = _type([ATTACHMENT]);
export const isPicture = _type([PICTURE]);
export const isWrapper = _type(wrapperComs);
export const isLayout = _type(layoutComs);
export const isDataTable = _type([DATATABLE]);
export const isTableLayout = _type([TABLELAYOUT]);
export const isMobileCom = _type(MOBILE);
export const isAddress = _type(ADDRESS);
export const isSignature = _type(SIGNATURE);
export const isDisableForDataTable = _type([ATTACHMENT, PICTURE, SIGNATURE, MAP, ADDRESS]);
export const isDisabledForDrag = _type([TABLELAYOUT]);
export const isVisible = com => com.visible;
export const needValid = com => !com.config.complex && isVisible(com);